home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / GLX / texvol / ui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  10.3 KB  |  362 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*----------------------------------------------------------------------------
  18.  * 
  19.  * file   : ui.c 
  20.  * 
  21.  * Author : Yusuf Attarwala
  22.  * Date   : Sep 93
  23.  * 
  24.  *---------------------------------------------------------------------------*/
  25.  
  26. #include "Xmincludes.h"
  27. #include "globals_vol.h"
  28. #include <Xm/Protocols.h>
  29. #include <X11/StringDefs.h>
  30.  
  31. static Arg args[40];
  32. static int argcnt;
  33.  
  34. static char *scrollCBs[] = {
  35.     XmNincrementCallback,
  36.     XmNdecrementCallback,
  37.     XmNdragCallback,
  38. };
  39.  
  40.  
  41. static char *toggles[] =   {"Draw Axes",
  42.                 "Degenerate",
  43.                             "Low Res",
  44.                 "DepthCue",
  45.                 "Do not blend",
  46.                             "Move Slice",
  47.                             "Display Clip Planes",
  48.                              };
  49.  
  50. static char *buttons[] =     {"Reset View",
  51.                               "Info/Help",
  52.                               "Exit"};
  53.  
  54. static char *views[] =     {"+x","+y","+z","-x","-y","-z"};
  55.  
  56. extern void   doExit();
  57. Widget clipButton[MAXCLIP];
  58.  
  59. void 
  60. createMenus(parent)
  61. Widget parent;
  62. {
  63.  
  64.     int i;
  65.     Widget tb;
  66.     void toggleCB(),clipOnOffCB(),clipMoveCB(),viewCB(),buttonCB();
  67.     Widget form,toggleFrame,clipFrame1,clipFrame2,viewFrame,buttonFrame;
  68.     Widget toggleRC,clipRC,clip2RC,viewRC,buttonRC;
  69.  
  70.     form = XtVaCreateManagedWidget("form",
  71.                             xmFormWidgetClass,parent,
  72.                             NULL);
  73.  
  74.     toggleFrame = XtVaCreateManagedWidget("ui",
  75.                      xmFrameWidgetClass, form,
  76.                      XmNleftAttachment,     XmATTACH_FORM,
  77.                      XmNleftOffset,         1,
  78.                      XmNtopAttachment,      XmATTACH_FORM,
  79.                      XmNtopOffset,          1,
  80.                      XmNrightAttachment,    XmATTACH_FORM,
  81.                      XmNrightOffset,        1,
  82.                      NULL);
  83.  
  84.     clipFrame1 = XtVaCreateManagedWidget("ui",
  85.                      xmFrameWidgetClass, form,
  86.                      XmNleftAttachment,   XmATTACH_FORM,
  87.                      XmNleftOffset,         1,
  88.                      XmNtopAttachment,    XmATTACH_WIDGET,
  89.                      XmNtopWidget,        toggleFrame,
  90.                      XmNrightAttachment,    XmATTACH_FORM,
  91.                      XmNrightOffset,        1,
  92.                      NULL);
  93.  
  94.     clipFrame2 = XtVaCreateManagedWidget("ui",
  95.                      xmFrameWidgetClass, form,
  96.                      XmNleftAttachment,   XmATTACH_FORM,
  97.                      XmNleftOffset,         1,
  98.                      XmNtopAttachment,    XmATTACH_WIDGET,
  99.                      XmNtopWidget,        clipFrame1,
  100.                      XmNrightAttachment,    XmATTACH_FORM,
  101.                      XmNrightOffset,        1,
  102.                      NULL);
  103.  
  104.     viewFrame =    XtVaCreateManagedWidget("ui",
  105.                          xmFrameWidgetClass, form,
  106.                          XmNtopAttachment,    XmATTACH_WIDGET,
  107.                          XmNtopWidget,        clipFrame2,
  108.                          XmNleftAttachment,   XmATTACH_FORM,
  109.                          XmNleftOffset,         1,
  110.                          XmNrightAttachment,    XmATTACH_FORM,
  111.                          XmNrightOffset,        1,
  112.                          NULL);
  113.     buttonFrame =    XtVaCreateManagedWidget("ui",
  114.                          xmFrameWidgetClass, form,
  115.                          XmNtopAttachment,    XmATTACH_WIDGET,
  116.                          XmNtopWidget,        viewFrame,
  117.                          XmNleftAttachment,   XmATTACH_FORM,
  118.                          XmNleftOffset,         1,
  119.                          XmNrightAttachment,    XmATTACH_FORM,
  120.                          XmNrightOffset,        1,
  121.                          XmNbottomAttachment, XmATTACH_FORM,
  122.                          NULL);
  123.  
  124.  
  125.     toggleRC = XtVaCreateManagedWidget("toggleRC",
  126.                   xmRowColumnWidgetClass, toggleFrame,
  127.                   XmNpacking,             XmPACK_TIGHT,
  128.                   XmNmarginWidth,         0,
  129.                   XmNmarginHeight,        0,
  130.                   NULL);
  131.  
  132.     for (i=0;i<XtNumber(toggles);i++) {
  133.         tb  = XtVaCreateManagedWidget(toggles[i],
  134.                            xmToggleButtonWidgetClass, toggleRC,
  135.                            XmNspacing,    2,
  136.                            NULL);
  137.         XtAddCallback(tb,XmNarmCallback,toggleCB,i);
  138.     }
  139.  
  140.     clipRC = XtVaCreateManagedWidget("ui",
  141.                   xmRowColumnWidgetClass, clipFrame1,
  142.                   XmNpacking,             XmPACK_TIGHT,
  143.                   XmNmarginWidth,         0,
  144.                   XmNmarginHeight,        0,
  145.                   XmNorientation,         XmHORIZONTAL,
  146.                   NULL);
  147.  
  148.     for (i=0;i<6;i++) {
  149.         clipButton[i] = XtVaCreateManagedWidget(" ",
  150.                            xmToggleButtonWidgetClass, clipRC,
  151.                            XmNspacing,    2,
  152.                            NULL);
  153.         XtAddCallback(clipButton[i],XmNarmCallback,clipOnOffCB,i);
  154.     }
  155.  
  156.     /*
  157.     clip2RC = XtVaCreateManagedWidget("ui",
  158.                   xmRowColumnWidgetClass, clipFrame2,
  159.                   XmNpacking,             XmPACK_TIGHT,
  160.                   XmNmarginWidth,         0,
  161.                   XmNmarginHeight,        0,
  162.                   XmNorientation,         XmHORIZONTAL,
  163.                   NULL);
  164.  
  165.     tb = XtVaCreateManagedWidget(" ",xmArrowButtonWidgetClass,clip2RC,
  166.                      XmNarrowDirection,XmARROW_LEFT,
  167.                      NULL);
  168.     XtAddCallback(tb,XmNactivateCallback,clipMoveCB,-1);
  169.  
  170.     tb = XtVaCreateManagedWidget(" ",xmArrowButtonWidgetClass,clip2RC,
  171.                      XmNarrowDirection,XmARROW_RIGHT,
  172.                      NULL);
  173.     XtAddCallback(tb,XmNactivateCallback,clipMoveCB,1);
  174.     */
  175.  
  176.     viewRC   = XtVaCreateManagedWidget("viewRC",
  177.                   xmRowColumnWidgetClass, viewFrame,
  178.                   XmNpacking,             XmPACK_TIGHT,
  179.                   XmNmarginWidth,         0,
  180.                   XmNmarginHeight,        0,
  181.                   XmNorientation,         XmHORIZONTAL,
  182.                   NULL);
  183.  
  184.     for (i=0;i<XtNumber(views);i++) {
  185.         tb  = XtVaCreateManagedWidget(views[i],
  186.                            xmPushButtonWidgetClass, viewRC,
  187.                            XmNspacing,    2,
  188.                            NULL);
  189.         XtAddCallback(tb,XmNactivateCallback,viewCB,i);
  190.     }
  191.  
  192.     buttonRC = XtVaCreateManagedWidget("buttonRC",
  193.                   xmRowColumnWidgetClass, buttonFrame,
  194.                   XmNpacking,             XmPACK_TIGHT,
  195.                   XmNmarginWidth,         0,
  196.                   XmNmarginHeight,        0,
  197.                   NULL);
  198.  
  199.     for (i=0;i<XtNumber(buttons);i++) {
  200.         tb  = XtVaCreateManagedWidget(buttons[i],
  201.                            xmPushButtonWidgetClass, buttonRC,
  202.                            XmNspacing,    2,
  203.                            NULL);
  204.         XtAddCallback(tb,XmNactivateCallback,buttonCB,i);
  205.     }
  206.  
  207. }
  208.  
  209. void
  210. toggleCB(w,i)
  211. Widget w;
  212. int i;
  213. {
  214.     switch(i) {
  215.     case 0 :
  216.         drawAxis = !drawAxis;    
  217.     drawScene();
  218.     break;
  219.     case 1 : 
  220.         degenMode = !degenMode;    
  221.     drawScene();
  222.     break;
  223.     case 2 : 
  224.         lightWeight = !lightWeight;    
  225.     drawScene();
  226.     break;
  227.     case 3 :
  228.     fog = !fog;
  229.     if (fog) {
  230.         defFog();
  231.     }
  232.     drawScene();
  233.     break;
  234.     case 4 :
  235.     dontBlend = !dontBlend;
  236.     drawScene();
  237.     break;
  238.     case 5 :
  239.     moveSlice = !moveSlice;
  240.     drawScene();
  241.     break;
  242.     case 6 :
  243.     displayClipPlanes = !displayClipPlanes;
  244.     drawScene();
  245.     break;
  246.     }
  247. }
  248.  
  249. void
  250. viewCB(w,which)
  251. Widget w;
  252. int which;
  253. {
  254.     specificView(which+1);
  255. }
  256.  
  257. void
  258. buttonCB(w,which)
  259. Widget w;
  260. int which;
  261. {
  262.     void infoDialog();
  263.     switch(which) {
  264.     case 0 :
  265.     resetView();
  266.     drawScene();
  267.     break;
  268.     case 1 :
  269.     infoDialog(w);
  270.     break;
  271.     case 2 : 
  272.     doExit();
  273.     break;
  274.     }
  275. }
  276.  
  277. void
  278. clipOnOffCB(w,which)
  279. Widget w;
  280. int which;
  281. {
  282.     int i;
  283.  
  284.     clip[which].onOff = !clip[which].onOff;
  285.  
  286.     if (clip[which].onOff==1) {
  287.     doClipping = 1;
  288.         activeClipPlane = which;
  289.     }
  290.     else {
  291.     doClipping = 0;
  292.         for (i=0;i<MAXCLIP;i++) {
  293.             if (clip[i].onOff==1) {
  294.                 doClipping = 1;
  295.                 break;
  296.             }
  297.         }
  298.     }
  299.     refresh = 1;
  300.     drawScene();
  301. }
  302.  
  303. void
  304. clipMoveCB(w,dir)
  305. Widget w;
  306. int dir;
  307. {
  308. }
  309.  
  310. static char infoText[] = "\
  311.             Volume Rendering using 2D and 3D textures\n\n\
  312.            Author : Yusuf Attarwala (SGI-Applications)\n\n\
  313. \
  314. To run the program in 3d texture mode, type texvol -tex 3\n\
  315. The default mode is 2d texture mode.\n\
  316. \n\
  317. In the 2D texture mode, the program maintains three orthogonal sets of planes\n\
  318. on which 2d textures are mapped. Depending upon the direction of view,\n\
  319. one set is selected and the textures from these planes are composited using \n\
  320. blendfunction.\n\
  321. \
  322. The data is 128 x 128 x 64 slices of 8 bit values.\n\
  323. \
  324. Left Mouse          : X and Y rotation\n\
  325. Middle Mouse        : Zoom \n\
  326. Left & Middle Mouse : Z rotation (order of click important)\n\
  327. Middle & Left Mouse : Panning (order of click important)\n\
  328. Up & Down Arrow Keys : Move active clipping plane\n\
  329. \
  330. In Low Res Mode, use Left and Right arrows to control\n\
  331. resolution.\n\
  332. \
  333. In Depth Cue Mode, use Left and Right arrows to control\n\
  334. fog density.\n\
  335.     ";
  336.  
  337.  
  338. void
  339. infoDialog(w)
  340. Widget w;
  341. {
  342.     Widget dialog;
  343.     XmString text;
  344.     char line[125];
  345.  
  346.     text = XmStringCreateLtoR(infoText,XmSTRING_DEFAULT_CHARSET);
  347.     XtSetArg(args[0],XmNmessageString,text);
  348.     XtSetArg(args[1],XmNautoUnmanage,False);
  349.     XtSetArg(args[2],XmNsymbolPixmap,NULL);
  350.     XtSetArg(args[3],XmNtitle,"Texture Volume  HELP");
  351.     dialog = XmCreateInformationDialog(w,"helpDialog",args,4);
  352.  
  353.     XmStringFree(text);
  354.  
  355.     XtUnmanageChild(XmMessageBoxGetChild(dialog,XmDIALOG_CANCEL_BUTTON));
  356.     XtUnmanageChild(XmMessageBoxGetChild(dialog,XmDIALOG_HELP_BUTTON));
  357.     XtAddCallback(dialog,XmNokCallback,XtDestroyWidget,NULL);
  358.  
  359.     XtManageChild(dialog);
  360.     XtPopup(XtParent(dialog),XtGrabNone);
  361. }
  362.